package com.wish.housing.controller;


import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wish.common.core.usconfig.common.MsgResult;
import com.wish.housing.entity.RoomReservationVO;
import com.wish.housing.entity.SysRegion;
import com.wish.housing.service.IRoomReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 预约房源表 前端控制器
 * </p>
 *
 * @author 
 * @since 2022-03-26
 */
@RestController
@RequestMapping("/reservation")
public class RoomReservationController {

	@Autowired
	IRoomReservationService roomReservationService;

	@GetMapping("/list")
	public MsgResult list(RoomReservationVO vo){
		IPage<RoomReservationVO> iPage = roomReservationService.listAll(vo);
		return MsgResult.succeed(iPage);
	}

	@GetMapping("/region")
	public MsgResult region(){
		List<SysRegion> regions = roomReservationService.regions();
		TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
		List<Tree<Integer>> build = TreeUtil.build(regions, 1, treeNodeConfig,
				(region, tree) -> {
					tree.setId(region.getRegionId());
					tree.setParentId(region.getParentId());
					tree.put("value",region.getRegionId());
					tree.put("label",region.getRegionName());
				});
		return MsgResult.succeed(build);
	}

	@PostMapping("updateStatus")
	public MsgResult updateStatus(@RequestBody RoomReservationVO roomReservationVO){
		roomReservationService.updateStatus(roomReservationVO);
		return MsgResult.succeed();
	}

}
